﻿using System.Collections.Generic;
using CivilRegistry.ControlledModel.Repository;

namespace CivilRegistry.ControlledModel
{
    /// <summary>
    /// The <see cref="RationCard"/> alter request object.
    /// </summary>
    public partial class RationCardAlterRequest
    {
        #region Local Fields

        /// <summary>
        /// The <see cref="RationCardAlterRequestRepository"/> instance.
        /// </summary>
        static RationCardAlterRequestRepository repository = new RationCardAlterRequestRepository();

        #endregion

        #region Methods

        #region Finder Methods

        /// <summary>
        /// Finds the <see cref="RationCardAlterRequest"/> by Id.
        /// </summary>
        /// <param name="id">The id of the <see cref="RationCardAlterRequest"/>.</param>
        /// <returns>Found <see cref="RationCardAlterRequest"/> object, null if not found.</returns>
        public static RationCardAlterRequest FindById(int id)
        {
            return repository.FindBy(rationCardAlterRequest => rationCardAlterRequest.RationCardAlterRequestId == id);
        }

        /// <summary>
        /// Finds the <see cref="RationCardAlterRequest"/> by requested <see cref="Person"/>.
        /// </summary>
        /// <param name="requestedPerson">The requested <see cref="Person"/>.</param>
        /// <param name="rationCardAlterRequestType">The <see cref="RationCardAlterRequestType"/>.</param>
        /// <returns>Found <see cref="RationCardAlterRequest"/> object, null if not found.</returns>
        public static RationCardAlterRequest FindByRequestedPerson(Person requestedPerson, RationCardAlterRequestType rationCardAlterRequestType)
        {
            return repository.FindBy(rationCardAlterRequest => rationCardAlterRequest.RequestedUser == requestedPerson && rationCardAlterRequest.RationCardAlterRequestType == rationCardAlterRequestType);
        }

        /// <summary>
        /// Finds the <see cref="RationCardAlterRequest"/> by applicable <see cref="Person"/>.
        /// </summary>
        /// <param name="applicablePerson">The applicable <see cref="Person"/>.</param>
        /// <param name="rationCardAlterRequestType">The <see cref="RationCardAlterRequestType"/>.</param>
        /// <returns>Found <see cref="RationCardAlterRequest"/> object, null if not found.</returns>
        public static RationCardAlterRequest FindByApplicablePerson(Person applicablePerson, RationCardAlterRequestType rationCardAlterRequestType)
        {
            return repository.FindBy(rationCardAlterRequest => rationCardAlterRequest.ApplicableUser == applicablePerson && rationCardAlterRequest.RationCardAlterRequestType == rationCardAlterRequestType);
        }

        /// <summary>
        /// Finds all <see cref="RationCardAlterRequest"/>s.
        /// </summary>
        /// <returns>Found <see cref="RationCardAlterRequest"/> objects, empty if none are found.</returns>
        public static List<RationCardAlterRequest> FindAll()
        {
            List<RationCardAlterRequest> rationCardAlterRequestList = new List<RationCardAlterRequest>();
            repository.FindAll().ForEach(rationCardAlterRequest => rationCardAlterRequestList.Add(rationCardAlterRequest));
            return rationCardAlterRequestList;
        }

        #endregion

        #region CUD Methods

        /// <summary>
        /// To insert the <see cref="RationCardAlterRequest"/>.
        /// </summary>
        /// <param name="rationCardAlterRequest">The <see cref="RationCardAlterRequest"/> to insert.</param>
        /// <returns>The inserted <see cref="RationCardAlterRequest"/> object.</returns>
        internal static RationCardAlterRequest Insert(RationCardAlterRequest rationCardAlterRequest)
        {
            return repository.Insert(rationCardAlterRequest);
        }

        /// <summary>
        /// To update the <see cref="RationCardAlterRequest"/>.
        /// </summary>
        /// <param name="rationCardAlterRequest">The <see cref="RationCardAlterRequest"/> to update.</param>
        /// <returns>The updated <see cref="RationCardAlterRequest"/> object.</returns>
        internal static RationCardAlterRequest Update(RationCardAlterRequest rationCardAlterRequest)
        {
            return repository.Update(rationCardAlterRequest);
        }

        /// <summary>
        /// To delete the <see cref="RationCardAlterRequest"/>.
        /// </summary>
        /// <param name="rationCardAlterRequest">The <see cref="RationCardAlterRequest"/> to delete.</param>
        internal static void Delete(RationCardAlterRequest rationCardAlterRequest)
        {
            repository.Delete(rationCardAlterRequest);
        }

        #endregion

        #endregion
    }
}
